/*
 * SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

@import (reference) '../../customize/src/less2/include/framework.less';
@import (reference) '../../customize/src/less2/include/sidebar-layout.less';
@import (reference) '../../customize/src/less2/include/tools.less';
@import (reference) '../../customize/src/less2/include/avatar.less';
@import (reference) '../../customize/src/less2/include/variables.less';

&.cp-app-calendar {

    .framework_min_main();
    .sidebar-layout_main();

    display: flex;
    flex-flow: column;

    .cp-toolbar-bottom-mid > div {
        color: @cryptpad_text_col;
        .cp-small { display: none; }
    }

    .flatpickr-calendar {
        z-index: 100001 !important; // Alertify is 100000
    }
    #cp-sidebarlayout-container #cp-sidebarlayout-rightside {
        padding: 0;
        & > div {
            margin: 0;
        }

        .cp-forcehide {
            display: none !important;
        }


        .tui-full-calendar-confirm {
            width: unset;
        }

        .tui-full-calendar-layout {
            background-color: @cp_sidebar-right-bg !important;
            color: @cryptpad_text_col;
            display: flex;
            flex-flow: column;
            .tui-full-calendar-week-container {
                min-height: 0;
                display: flex;
                flex-flow: column;
                .tui-full-calendar-vlayout-area {
                    display: flex;
                    flex-flow: column;
                    flex: 1;
                    min-height: 0;
                    & > div:last-child {
                        flex: 1;
                        min-height: 0;
                    }
                }
            }

            .tui-full-calendar-schedule-title {
                font-size: @colortheme_app-font-size;
            }
            .tui-full-calendar-weekday-filled {
                background-color: @cp_dropdown-bg-hover !important;
            }

            .tui-full-calendar-timegrid-hourmarker-time {
                color: @cp_calendar-now !important;
            }
            .tui-full-calendar-timegrid-hourmarker-line-left, .tui-full-calendar-timegrid-hourmarker-line-today {
                border-color: @cp_calendar-now !important;
            }
            .tui-full-calendar-timegrid-todaymarker {
                background-color: @cp_calendar-now !important;
            }

            .tui-full-calendar-month {
                display: flex;
                flex-flow: column;
                & > div:last-child {
                    display: flex;
                    flex-flow: column;
                    flex: 1;
                    min-height: 0;
                    overflow: hidden;
                }
                .tui-full-calendar-today .tui-full-calendar-weekday-grid-date-decorator {
                    background-color: @cp_calendar-now !important;
                    color: @cp_calendar-now-fg !important;
                }
                .tui-full-calendar-weekday-schedule-time .tui-full-calendar-weekday-schedule-title {
                    color: @cryptpad_text_col !important;
                }
                .tui-full-calendar-extra-date {
                    .tui-full-calendar-weekday-grid-date {
                        color: @cp_sidebar-hint !important;
                        opacity: 0.5;
                    }
                }
                .tui-full-calendar-weekday-grid-date {
                    color: @cryptpad_text_col !important;
                }
                .tui-full-calendar-month-dayname-item span {
                    color: @cryptpad_text_col !important;
                }
            }
            .tui-full-calendar-dayname * {
                color: @cryptpad_text_col !important;
            }
                .tui-full-calendar-month-more {
                    background-color: @cp_sidebar-right-bg !important;
                    color: @cryptpad_text_col;
                    span {
                        color: @cryptpad_text_col !important;
                    }
                }

            .tui-full-calendar-floating-layer.cp-calendar-popup-flex {
                top: 0 !important;
                left: 0 !important;
                right: 0 !important;
                bottom: 0 !important;
                justify-content: center !important;
                align-items: center !important;
                .tui-full-calendar-popup {
                    width: 540px;
                    max-width: 100%;
                    max-height: 100%;
                    border-radius: @variables_radius_L;
                    @media screen and (max-width : @browser_media-medium-screen){
                        position: fixed;
                        top: 5.5rem;
                        overflow-y: auto;
                        max-height: calc(100% - 6rem);
                    }
                }
            }
            #tui-full-calendar-popup-arrow {
                display: none !important;
            }
        }
        .tui-full-calendar-timegrid-timezone {
            background-color: @cp_sidebar-right-bg !important;
            .tui-full-calendar-timegrid-hour {
                color: @cryptpad_text_col !important;
            }
            color: @cryptpad_text_col;
        }
        .tui-full-calendar-timegrid-gridline, .tui-full-calendar-time-date {
            border-color: @cp_calendar-border !important;
        }
        .tui-full-calendar-splitter, .tui-full-calendar-left, .tui-full-calendar-dayname-container, .tui-full-calendar-weekday-grid-line {
            border-color: @cp_calendar-border !important;

        }
        .tui-full-calendar-popup-container {
            .tui-full-calendar-section-allday{
                &:focus {
                    outline: @cryptpad_color_brand solid 2px;
                }
            }
            min-width: 100%;
            background: @cp_flatpickr-bg;
            color: @cryptpad_text_col;
            border-radius: @variables_radius_L;
            font-weight: normal;
            .tui-full-calendar-icon:not(.tui-full-calendar-calendar-dot):not(.tui-full-calendar-dropdown-arrow):not(.tui-full-calendar-ic-checkbox):not(.tui-full-calendar-dropdown-arrow-custom):not(svg) {
                display: none;
            }
            .tui-full-calendar-icon {
                text-align:center;
                flex-shrink: 0;
            }
            .tui-full-calendar-dropdown-arrow-custom {
                display: inline-flex;
                align-items: center;
                svg {
                    font-size: @variables_button-font-size;
                    margin: 0;
                }
            }
            .tui-full-calendar-popup-detail-item {
                display: flex;
                margin-bottom: 0.3rem;
                align-items: center;
                .event-location {
                    display: flex;
                    align-items: center;
                }
                &.tui-full-calendar-popup-detail-item-separate {
                    &>span {
                        display: flex;
                        width: 100%;
                        align-items: center;
                    }
                    .event-description {
                        display: block;
                        line-height: 1.1em;
                        p, ul {
                            margin:0.1rem;
                        }
                    }
                }
                a {
                    border-radius: @variables_radius;
                    color: @cryptpad_color_link;
                    text-decoration: underline;
                    &:focus-visible{
                        outline: @variables_focus_style;
                    }
                }
                span {
                    overflow: hidden;
                    word-break: break-word;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    .event-description{
                        white-space: normal;
                    }
                }
            }
            .tui-full-calendar-section-button-save {
                height: 40px;
                .btn-primary { // Update button
                    margin-right: 0;
                    display: flex;
                }
            }

        }
        li.tui-full-calendar-popup-section-item {
            padding: 0 6px;
            min-height: 32px;
        }
        .tui-full-calendar-popup-section-item {
            height: auto;
            margin: 0;
            &:not(li):not(button) {
                padding: 0;
                margin-top: 0.5rem;
            }
            #tui-full-calendar-schedule-calendar {
                font-size: @variables_button-font-size;
                width: 179px;
                top: 0;
            }
            &:not(button) {
                border: none;
                display: inline-flex;
                align-items: center;
                &:hover {
                    background-color: @cp_dropdown-bg-hover;
                }
                .tui-full-calendar-content {
                    text-overflow: ellipsis;
                    overflow: hidden;
                    white-space: nowrap;
                    font: @colortheme_app-font;
                    font-size: @colortheme_app-font-size;
                    padding: 0 10px;
                    &:focus{
                        outline: @cryptpad_color_brand solid 2px;
                    }
                }
                input { flex: 1; }
            }
        }
        .tui-full-calendar-section-date-dash {
            height: auto;
        }
        .tui-full-calendar-section-title, .tui-full-calendar-section-location, .tui-full-calendar-section-body {
            width: 100%;
        }
        .tui-full-calendar-dropdown-menu {
            top: 38px;
            width: 221px; // same as button
            background-color: @cp_dropdown-bg;
            color: @cp_dropdown-fg;
            border-radius: 0 0 @variables_radius @variables_radius;
            li:focus-visible {
                outline: @cryptpad_color_brand solid 2px;
            }
        }
        button.tui-full-calendar-popup-section-item.btn.btn-secondary {
            &[aria-expanded="true"] {
                border-radius: @variables_radius @variables_radius 0 0;
            }
        }
        .tui-full-calendar-section-state, #tui-full-calendar-schedule-private {
            display: none !important;
        }

        .tui-full-calendar-popup:not(.tui-full-calendar-popup-detail) {
            .tui-full-calendar-section-calendar {
                width: 221px; // 50%
            }
            .tui-full-calendar-popup-section {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
                min-height: 0; // override default tui 40px
                .tui-full-calendar-section-start-date, .tui-full-calendar-section-end-date {
                    flex: 1;
                }
                .tui-full-calendar-section-allday {
                    width: 100%;
                    height: 32px;
                    border-radius: @variables_radius;
                    input[type="checkbox"].tui-full-calendar-checkbox-square:checked + span {
                        background: url();
                    }
                    .tui-full-calendar-ic-checkbox {
                        margin-left: 1px;
                        border-radius: 2px;
                    }
                }
                .CodeMirror {
                    margin-top: 0.5rem;
                    background: @cp_forms-bg !important;
                    color: @cryptpad_text_col;
                    border: 1px solid @cp_forms-border;
                    border-radius: @variables_radius;
                    width: 100%;
                    height: 80px;
                    font: @colortheme_app-font;
                    line-height: initial;
                    padding-left: 0.3rem;
                    pre {
                        margin: 0;
                        font-family: inherit;
                        font-size: inherit;
                        line-height: inherit;
                    }
                    * {
                        box-sizing: content-box;
                    }
                }
                .CodeMirror-placeholder {
                    color: @cp_forms-placeholder;
                }
            }
        }
        .tui-full-calendar-popup-detail {
            font: @colortheme_app-font;
            color: @cryptpad_text_col;
            box-shadow: @cryptpad_ui_shadow;
            .tui-full-calendar-popup-container {
                padding-bottom: 17px;
            }
            .tui-full-calendar-popup-detail-date {
                font-size: @variables_button-font-size;
            }
            .tui-full-calendar-section-button {
                margin-top: 10px;
                border: 0;
                display: flex;
                align-items: start;
                button {
                    flex: 1;
                    margin: 0;
                    display: inline-flex;
                    justify-content: center;
                }
            }
            .tui-full-calendar-popup-top-line {
                border-radius: 10px 10px 0px 0px;
                height: 10px;
            }
            .tui-full-calendar-popup-vertical-line {
                visibility: hidden;
                width: 10px;
            }
        }

        .cp-recurrence-label, .cp-notif-label {
            color: @cryptpad_text_col;
            display: inline-flex;
            align-items: center;
        }

        .cp-calendar-recurrence-container {
            margin-top: 0.5rem;
            display: inline-flex;
            gap: 0.5rem;
            .cp-calendar-rec-translated-str {
                margin-top: 0.5rem;
            }
        }

        .cp-dropdown-container button {
            font-size: @variables_button-font-size;
        }

        .cp-calendar-add-notif {
            flex-flow: column;
            align-items: baseline !important;
            margin: 0.5rem 0;
            font-size: @colortheme_app-font-size;
            & > div {
                display: flex;
                align-items: center;
                flex-direction: row;
                flex-wrap: wrap;
                gap: 0.5rem;
            }
            .cp-calendar-notif-list-container {
                width: 100%;
                margin-bottom: 0.5rem;
            }
            .cp-calendar-notif-list {
                display: flex;
                flex-flow: column;
                flex: 1;
                min-width: 150px;
                gap: 2px;
                &:empty {
                    display: none;
                }
                .cp-notif-entry {
                    display: flex;
                    margin-bottom: 0;
                    border-radius: @variables_radius;
                    background-color: fade(@cryptpad_text_col, 10%);
                    padding: 0.25rem;
                    .cp-notif-value {
                        width: 75%;
                        display: inline-flex;
                        line-height: 30px;
                        vertical-align: middle;
                        flex-grow: 1;
                        .cp-before {
                            flex: 1;
                            min-width: 0;
                        }
                    }
                    span:not(:last-child) {
                        margin: 0;
                        margin-right: 0.3rem;
                    }
                    span:first-child {
                        margin-left: 0.3rem;
                    }
                    .btn-danger-outline {
                        display: inline-flex;
                        align-items: center;
                        background-color: transparent;
                        color: @cryptpad_text_col;
                        border-color: @cryptpad_text_col;
                        &:hover {
                            color: @cp_buttons-red-color;
                            background-color: @cp_buttons-red;
                            border-color: @cp_buttons-red;
                        }
                        svg {
                            margin-right: 0;
                        }
                      }
                }
            }
            .cp-notif-empty {
                display: none;
                margin-bottom: 2px;
                border-radius: @variables_radius;
                background-color: fade(@cryptpad_text_col, 10%);
                padding: 0.25rem 0.5rem;
                line-height: 30px;
            }
            .cp-calendar-notif-list:empty ~ .cp-notif-empty {
                display: block;
            }
            .cp-calendar-notif-form {
                align-items: center;
                .cp-calendar-notif-form-buttons {
                    display: inline-flex;
                    align-items: center;
                    gap: 0.5rem;
                    font-size: @variables_button-font-size;
                    & > input {
                        height: 40px;
                    }
                    .tui-full-calendar-content{
                        &:focus{
                            outline: @cryptpad_color_brand solid 2px;
                        }
                    }
                    .btn-primary-outline {
                        svg {
                            margin: 0;
                        }
                    }
                }
                // margin-bottom: 20px;
                input {
                    width: 80px;
                }
            }
        }

        .cp-calendar-close {
            top: 17px;
            right: 17px;
            height: auto;
            margin-right: 0px;
            line-height: initial;
            border: 1px solid;
            &:not(:hover) {
                background: transparent;
            }
            svg {
                margin: 0;
            }
        }

    }

    .cp-calendar-rec-inline, .cp-calendar-rec-block {
        &:not(:last-child) {
            margin-bottom: 10px;
        }
    }
    .cp-calendar-rec-inline {
        display: flex;
        flex-flow: row;
        align-items: center;
        & > *:not(:first-child) { margin-left: 5px; }
        .cp-dropdown-container {
            position: unset;
        }
        input[type="number"] {
            width: 80px !important;
            margin-bottom: 0 !important;
        }
        .cp-checkmark {
            margin-right: 0.5rem;
        }
    }
    .cp-calendar-rec-block {
        .cp-calendar-rec-block-title {
            margin-bottom: 0.5rem !important;
        }
        .cp-radio {
            margin-bottom: 0.5rem;
        }
        input[type="radio"]:not(:checked) ~ .cp-checkmark-label {
            input {
                filter: grayscale(1);
            }
        }
        .cp-checkmark-label {
            & > *:not(:first-child) { margin-left: 5px; }
            width: 100%;
            //height: 26px;
            display: flex;
            align-items: center;
            & > input {
                margin-bottom: 0 !important;
            }
            input {
                display: inline;
                height: 24px !important;
                padding: 0 5px !important;
            }
            input[type="text"] {
                width: 200px !important;
            }
            input[type="number"] {
                width: 80px !important;
                margin-bottom: 0 !important;
            }
        }
    }
    #cp-calendar-rec-monthly-pick ~ .cp-checkmark-label {
        display: flex;
        align-items: center;
        & > span {
            margin-right: 20px;
        }
    }
    button.cp-calendar-pick-el {
        display: flex;
        align-items: center;
        justify-content: center;
        &:not(:last-child) {
            margin-right: 5px;
        }
    }
    div.cp-calendar-weekly-pick {
        button {
            width: 50px;
        }
    }
    div.cp-calendar-monthly-pick {
        display: flex;
        flex-flow: column;
        & > div {
            display: flex;
            &:not(:last-child) {
                margin-bottom: 5px;
            }
            button {
                height: 25px;
                width: 25px;
                &.lastday {
                    width: 115px;
                }
            }
        }
    }

    .tui-full-calendar-ic-repeat-b {
        display: none;
        & ~ * {
            display: none;
        }
    }

    #cp-toolbar .cp-calendar-browse {
        display: flex;
        align-items: center;
        button {
            color: @cp_toolbar-fg;
            border-color: @cp_toolbar-fg;
            &:hover {
                background-color: fade(@cp_toolbar-fg, 50%);
                cursor: pointer;
            }
            svg {
                margin: 0;
            }
        }
    }

    .cp-calendar-newevent {
        &:hover {
            cursor: pointer;
        }
    }

    .cp-toolbar-bottom-right button, .cp-toolbar-user button {
        &:hover {
            cursor: pointer;
        }
    }

    #cp-sidebarlayout-leftside {
        & > div {
            padding: 10px
        }
        .cp-calendar-new {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .cp-calendar-list {
            overflow-y: auto;
            .cp-calendar-team {
                height: 30px;
                .avatar_main(30px);
                .cp-avatar {
                    margin-right: 10px;
                }
                .cp-name {
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }
                display: flex;
                align-items: center;
                justify-content: center;
                margin: 5px 0 10px 0;
                &:not(:first-child) {
                    margin-top: 30px;
                }
            }
            @media screen and (max-width: @browser_media-medium-screen) {
                .cp-calendar-entries {
                    display: none;
                }

                .cp-calendar-entries.visible {
                    display: block;
                }
            }
            .cp-calendar-entries {
                margin-bottom: 10px;
            }
            .cp-calendar-entry {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 5px;
                border-radius: @variables_radius;
                background-color: @cp_sidebar-left-bg;
                svg {
                    margin-right: 0.25rem;
                    flex-shrink: 0;
                }
                .cp-calendar-icon, .cp-calendar-actions {
                    svg {
                        margin: 0;
                    }
                }
                &:not(.cp-unclickable) {
                    cursor: pointer;
                }
                .cp-dropdown-container {
                    position: initial;
                    .cp-dropdown-content{
                        svg {
                            margin-right: @variables_icon_margin;
                        }
                        @media screen and (max-width: 600px)
                        {
                            left: 50%;
                            min-width: 45%;
                        }
                    }
                }
                button.cp-calendar-actions {
                    background-color: transparent;
                    &:hover {
                        background-color: @cp_sidebar-left-bg;
                    }
                }
                &.cp-ghost {
                    padding: 0;
                    margin-top: 0.5rem;
                    button {
                        .tools_unselectable();
                        cursor: pointer;
                        width: 100%;
                        display: flex;
                        justify-content: space-between;
                        background: transparent;
                        border: 1px solid @cryptpad_text_col;
                        border-radius: @variables_radius;
                        padding: 5px;
                        height: 36px;
                        font: @colortheme_app-font;
                        align-items: center;
                        color: @cryptpad_text_col;
                        &:hover {
                            background-color: @cp_sidebar-left-active;
                            color: @cp_sidebar-left-active-fg;
                            border: 0px;
                        }
                        &:focus-visible {
                            outline: @variables_focus_style;
                        }
                    }
                }
                &:not(:last-child) {
                    margin-bottom: 10px;
                }
                &:hover {
                    background: @cp_sidebar-left-item-bg;
                }
                &.cp-restricted {
                    color: @cp_drive-header-fg;
                }
                .cp-calendar-icon {
                    width: 30px;
                    display: inline-flex;
                    height: 30px;
                    align-items: center;
                    justify-content: center;
                    border-radius: @variables_radius;
                    flex-shrink: 0;
                }
                &.cp-active {
                    background-color: @cp_sidebar-left-item-bg;
                    .cp-calendar-inactive {
                        display: none;
                    }
                }
                &:not(.cp-active) {
                    .cp-calendar-icon {
                        background: transparent !important;
                    }
                    .cp-calendar-active {
                        display: none;
                    }
                }
                .tools_unselectable();
                .cp-calendar-color {
                    display: inline-block;
                    border-radius: 50%;
                    width: 15px;
                    height: 15px;
                    flex-shrink: 0;
                }
                .cp-calendar-title {
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    padding: 0 5px;
                    flex: 1;
                    text-align: center;
                }
            }
        }
    }
    .cp-calendar-colorpicker {
        width: 100px;
        height: 25px;
        cursor: pointer;
        border: 1px solid @cp_forms-border;
    }

    @media (max-width: @browser_media-medium-screen) {
        .cp-calendar-notif-list-container, .cp-calendar-notif-form {
            flex-direction: column;
            align-items: unset !important;
            gap: 0.5rem;
        }
        .cp-calendar-newevent {
            svg {
                margin: 0;
            }
            span {
                display: none;
            }
        }
        .tui-full-calendar-dayname-leftmargin, .tui-full-calendar-timegrid-right {
            margin-left: 40px !important;
        }
        .tui-full-calendar-allday-left, .tui-full-calendar-timegrid-left {
            width: 40px !important;
        }
        .tui-full-calendar-dayname > span {
            display: flex;
            flex-flow: column;
            line-height: 0;
            justify-content: center;
            align-items: center;
            height: 100%;
        }
        .tui-full-calendar-dayname * {
            font-size: 11px;
            line-height: initial;
            height: auto;
        }
        .cp-toolbar-bottom-mid > div {
            :not(:first-child) {
                display: none;
            }
            :first-child {
                display: inline-block;
            }
        }
    }

}

